<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Main extends MY_Controller {
    
    public function __construct() {
        parent::__construct();
        $this->load->model('setting_model');
        $this->load->model('bookmarks_model');
//        $this->load->model('user_profiles','user_profiles_model');
        $this->load->model('tree_model');
    }

    public function index(){
        $this->setting_model->validate_cookie();
        
        $data['title'] = "Будущее зависит от Статистики! (".$this->session->userdata['login'].")";
        $data['head'] = 'Главная страница';
        $data['content'] = '<br>';
//        $data['content_view'] = 'content_view';
        $data['user_name'] = $this->session->userdata['login'];

//        $data['bookmarks'] = $this->bookmarks_model->show_bookmarks_list(0,$this->bookmarks_model->get_bookmarks(),$this->user_profiles_model->get_u_bookmarks()); //v1.0
//        $data['bookmarks'] = $this->bookmarks_model->get_tree_bookmarks(); //v2.0
//        $data['content']  .= $this->tree_model->get_tree_directory();
//        $data['settings']  = $this->setting_model; //->get_settings();
        $data['settings']  = $this->setting_model->get_settings();
        
        
        
        // new data
        $data['username'] = $this->session->userdata['login'];
        $data['bookmarks_content'] = $this->bookmarks_model->get_tree_bookmarks();
        $data['tree_content'] = $this->tree_model->get_tree_directory();

        $this->load->view('ver2/main_view',$data);
//        $this->load->view('main_view',$data);
    }
    
    public function search(){
        
        if(!$this->role_model->isAdminRole()) {
            redirect();
        }
        
        $this->load->model('search_model');
        
        $this->setting_model->validate_cookie();
        $data['settings']  = $this->setting_model; //->get_settings();
        
        $search_word = $this->uri->segment(3,'');
        
        if(isset($_POST['btnSearch'])){
//            $search_word = preg_replace("/['\"-]/", "", $_POST['search']);
            $search_word = filter_input(INPUT_POST, 'search');
        }
        
        // new data
        $data['title'] = "Поиск ".$search_word;
        $data['username'] = $this->session->userdata['login'];
//        $data['bookmarks_content'] = "<h3>Результаты поиска</h3>"; //$this->bookmarks_model->get_tree_bookmarks();
        $data['search_content'] = $this->search_model->show_search_result($search_word); //$this->tree_model->get_tree_directory();

        $this->load->view('ver2/search_view',$data);
    }
        
}
